package net.kansun.impl;

import net.kansun.Parser;
import net.kansun.Segment;

import java.util.Map;

/**
 * An implementation of {@link Parser} that parses a specific segment of data.
 */
public class SegmentParser implements Parser {

   private Map<Segment, Parser> parserMapping;

   @Override
   public String parse(Long source) {

      if (source / 100 > 0) {
         return parserMapping.get(Segment.HUNDREDS).parse(source);
      }

      if (source / 10 > 0) {
         return parserMapping.get(Segment.TENS).parse(source);
      }

      if (source / 1 > 0) {
         return parserMapping.get(Segment.UNITS).parse(source);
      }

      return "";
   }

   public void setParserMapping(Map<Segment, Parser> parserMapping) {
      this.parserMapping = parserMapping;
   }
}
